package com.kcnet.qk.app;

import android.content.Context;
import android.content.SharedPreferences;

import com.kcnet.qk.constant.Const;
import com.kcnet.qk.constant.StringConst;
import com.kcnet.qk.service.AutoAddPeopleService;
import com.kcnet.qk.util.FileUtils;
import com.kcnet.qk.util.PreferenceHelper;
import com.kcnet.qk.util.RootShell;

import cn.jesse.nativelogger.NLogger;
import cn.jesse.nativelogger.formatter.SimpleFormatter;
import cn.jesse.nativelogger.logger.LoggerLevel;

/**
 * Created by Administrator on 2018/4/27.
 */

public class AppContext {

    private static AppContext mRongCloudInstance;

    private AutoAddPeopleService mService;
    private Context mContext;

    public static long taskId = -1;
    public static long taskStartTime;
    public static long taskType = -1;

    public static int languen = 1; //1 简体中文 2繁体 3 英文

    public AppContext(Context mContext) {
        this.mContext = mContext;
        RootShell.getSu();

        languen  = PreferenceHelper.getInt(Const.LAGUANGE,1);

        NLogger.getInstance()
                .builder()
                .tag("APP")
                .loggerLevel(LoggerLevel.DEBUG)
                .fileLogger(true)
                .fileDirectory(FileUtils.getLogStorageDirectory())
                .fileFormatter(new SimpleFormatter())
                .expiredPeriod(3)
                .build();
        //initListener();
    }

    /**
     * 初始化 RongCloud.
     *
     * @param context 上下文。
     */
    public static void init(Context context) {

        if (mRongCloudInstance == null) {
            synchronized (AppContext.class) {

                if (mRongCloudInstance == null) {
                    mRongCloudInstance = new AppContext(context);
                }
            }
        }

    }




    /**
     * 获取RongCloud 实例。
     *
     * @return RongCloud。
     */
    public static AppContext getInstance() {
        return mRongCloudInstance;
    }

    public Context getContext() {
        return mContext;
    }

    public AutoAddPeopleService getmService() {
        return mService;
    }

    public void setmService(AutoAddPeopleService mService) {
        this.mService = mService;
    }
}
